package com.cloudcc.mobile.adapter;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cloudcc.cloudframe.adapter.CommonAdapter;
import com.cloudcc.cloudframe.adapter.ViewHolder;
import com.cloudcc.cloudframe.model.Album;
import com.cloudcc.mobile.AppContext;
import com.cloudcc.mobile.R;
import com.cloudcc.mobile.util.photo.Constants;
import com.cloudcc.mobile.util.photo.Util;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * 手机中 相册 的 列表的适配器
 * @author seven
 *
 */
public class AlbumListAdapter extends CommonAdapter<Album> {

	private OnMyItemClickListener mListener;
	
	public AlbumListAdapter(Context mContext) {
		super(mContext);
	}

	@Override
	public void convert(ViewHolder vh,final Album t) {
		
		final int pos =vh.getPostion();

		TextView tvAlbumName = vh.getView(R.id.choicename);
		ImageView ivChoice = vh.getView(R.id.icon_choice);
		LinearLayout llContainer = vh.getView(R.id.bg);
		
		llContainer.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (mListener!=null) {
					mListener.onSelectAlbum(t, pos);
				}
			}
		});

		String name = "";
		if (t.getmName().length() > 8) {
			name = t.getmName().substring(0, 7);
			tvAlbumName.setText(name + t.getmNum());
		} else {
			tvAlbumName.setText(t.getmName() + t.getmNum());
		}
		llContainer.setBackgroundColor(AppContext.getApp().getResources()
				.getColor(R.color.ban_touming_progress));

		ImageLoader.getInstance().displayImage("file://" + t.mCoverUrl,
				ivChoice, Constants.image_display_options,
				new Util.AnimateFirstDisplayListener());
	}

	/**
	 * 设置监听
	 * @param l
	 */
	public void setItemListener(OnMyItemClickListener l){
		this.mListener =l;
	}
	
	
	@Override
	public int getLayoutId() {
		return R.layout.choice_photo_item;
	}
	
	
	/**
	 * 选中 事件监听
	 * @author seven
	 *
	 */
	public interface OnMyItemClickListener{
		/**
		 * 选中 相册 之后
		 * @param t
		 * @param pos
		 */
		void onSelectAlbum(Album t,int pos);
	}

}
